package com.eastfair.auth.controller;

import com.eastfair.auth.service.MenuRoleService;
import com.eastfair.auth.entity.MenuRole;
import com.eastfair.auth.dto.MenuRoleSaveDTO;
import com.eastfair.auth.dto.MenuRoleUpdateDTO;
import com.eastfair.auth.dto.MenuRolePageQuery;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 
 * </p>
 *
 * @author ligang
 * @date 2021-07-23
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/menuRole")
@Api(value = "MenuRole", tags = "")
public class MenuRoleController extends SuperController<MenuRoleService, Long, MenuRole, MenuRolePageQuery, MenuRoleSaveDTO, MenuRoleUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<MenuRole> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<MenuRole> menuRoleList = list.stream().map((map) -> {
            MenuRole menuRole = MenuRole.builder().build();
            //TODO 请在这里完成转换
            return menuRole;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(menuRoleList));
    }
}
